<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'form/guardable_form.class.php');
require_once(TANGRA_MAIN_DIR.'form/fields/file/form_field_file.class.php');
require_once(TANGRA_MAIN_DIR.'/form/static_html_form_generator.class.php');


class Image_Upload_Form extends Guardable_Form {
	function __construct($max_size) {
		parent::__construct('image_upload', 'admin/modules/tangra_cms/image/image_upload.php');

		$f_image = new Form_Field_File('image', true, $max_size);
		$f_image->add_potential_error('invalid_file');
		$f_image->add_potential_error('invalid_extension');
		$f_image->add_potential_error('maximum_width_exceeded');
		$f_image->add_potential_error('maximum_height_exceeded');
		$f_image->add_potential_error('xy_invalid_ratio');

		$this->add_field($f_image);
	}


	public function generate_html() {
		$html_gen = new Static_HTML_Form_Generator($this, 'modules/form_html_tpl_static_ajax_metallic_en', 'en');
		$html_gen->create_default_tpl_maps();
		$html_gen->change_field_p_error_map_entry('image', 'invalid_file', 'modules/tangra_cms/forms/field_errors/image_upload/field_error_invalid_file.tpl');
		$html_gen->change_field_p_error_map_entry('image', 'invalid_extension', 'modules/tangra_cms/forms/field_errors/image_upload/field_error_invalid_extension.tpl');
		$html_gen->change_field_p_error_map_entry('image', 'maximum_width_exceeded', 'modules/tangra_cms/forms/field_errors/image_upload/field_error_maximum_width_exceeded.tpl');
		$html_gen->change_field_p_error_map_entry('image', 'maximum_height_exceeded', 'modules/tangra_cms/forms/field_errors/image_upload/field_error_maximum_height_exceeded.tpl');
		$html_gen->change_field_p_error_map_entry('image', 'xy_invalid_ratio', 'modules/tangra_cms/forms/field_errors/image_upload/field_error_xy_invalid_ratio.tpl');

		printbr('<pre>');
		printbr(htmlentities($html_gen->get_static_html()));
		printbr('</pre>');
	}
}
